package com.openbravo.pos.inventory;

import com.openbravo.basic.BasicException;
import com.openbravo.data.loader.DataRead;
import com.openbravo.data.loader.Datas;
import com.openbravo.data.loader.PreparedSentence;
import com.openbravo.data.loader.SentenceExecTransaction;
import com.openbravo.data.loader.SerializerRead;
import com.openbravo.data.loader.SerializerWriteBasicExt;
import com.openbravo.data.loader.Session;
import com.openbravo.data.model.Field;
import com.openbravo.data.model.Row;
import com.openbravo.data.user.BrowsableEditableData;
import com.openbravo.data.user.EditorRecord;
import com.openbravo.data.user.ListProviderCreator;
import com.openbravo.data.user.SaveProvider;
import com.openbravo.format.Formats;
import com.openbravo.pos.forms.AppLocal;
import com.openbravo.pos.forms.AppView;
import com.openbravo.pos.panels.JPanelTable2;
import com.openbravo.pos.reports.JParamsLocation;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.UUID;

public class ProductsWarehousePanel extends JPanelTable2
{
  private JParamsLocation m_paramslocation;
  private ProductsWarehouseEditor jeditor;

  protected void init()
  {
    this.m_paramslocation = new JParamsLocation();
    this.m_paramslocation.init(this.app);
    this.m_paramslocation.addActionListener(new ReloadActionListener( ));
    this.row = new Row(new Field[] { new Field("ID", Datas.STRING, Formats.STRING), new Field("PRODUCT_ID", Datas.STRING, Formats.STRING), new Field(AppLocal.getIntString("label.prodref"), Datas.STRING, Formats.STRING, true, true, true), new Field(AppLocal.getIntString("label.prodname"), Datas.STRING, Formats.STRING, true, true, true), new Field("LOCATION", Datas.STRING, Formats.STRING), new Field("STOCKSECURITY", Datas.DOUBLE, Formats.DOUBLE), new Field("STOCKMAXIMUM", Datas.DOUBLE, Formats.DOUBLE), new Field("UNITS", Datas.DOUBLE, Formats.DOUBLE) });
    this.lpr = new ListProviderCreator(new PreparedSentence(this.app.getSession(), "SELECT L.ID, P.ID, P.REFERENCE, P.NAME,L.STOCKSECURITY, L.STOCKMAXIMUM, COALESCE(S.SUMUNITS, 0) FROM PRODUCTS P LEFT OUTER JOIN (SELECT ID, PRODUCT, LOCATION, STOCKSECURITY, STOCKMAXIMUM FROM STOCKLEVEL WHERE LOCATION = ?) L ON P.ID = L.PRODUCT LEFT OUTER JOIN (SELECT PRODUCT, SUM(UNITS) AS SUMUNITS FROM STOCKCURRENT WHERE LOCATION = ? GROUP BY PRODUCT) S ON P.ID = S.PRODUCT ORDER BY P.NAME", new SerializerWriteBasicExt(new Datas[] { Datas.OBJECT, Datas.STRING }, new int[] { 1, 1 }), new WarehouseSerializerRead( )), this.m_paramslocation);
      SentenceExecTransaction local1 = new SentenceExecTransaction(this.app.getSession())
    {
      public int execInTransaction(Object paramObject)
        throws BasicException
      {
        Object[] arrayOfObject = (Object[])(Object[])paramObject;
        if (arrayOfObject[0] == null)
        {
          arrayOfObject[0] = UUID.randomUUID().toString();
          return new PreparedSentence(ProductsWarehousePanel.this.app.getSession(), "INSERT INTO STOCKLEVEL (ID, LOCATION, PRODUCT, STOCKSECURITY, STOCKMAXIMUM) VALUES (?, ?, ?, ?, ?)", new SerializerWriteBasicExt(ProductsWarehousePanel.this.row.getDatas(), new int[] { 0, 4, 1, 5, 6 })).exec(paramObject);
        }
        return new PreparedSentence(ProductsWarehousePanel.this.app.getSession(), "UPDATE STOCKLEVEL SET STOCKSECURITY = ?, STOCKMAXIMUM = ? WHERE ID = ?", new SerializerWriteBasicExt(ProductsWarehousePanel.this.row.getDatas(), new int[] { 5, 6, 0 })).exec(paramObject);
      }
    };
    this.spr = new SaveProvider(local1, null, null);
    this.jeditor = new ProductsWarehouseEditor(this.dirty);
  }

  public Component getFilter()
  {
    return this.m_paramslocation.getComponent();
  }

  public EditorRecord getEditor()
  {
    return this.jeditor;
  }

  public void activate()
    throws BasicException
  {
    this.m_paramslocation.activate();
    super.activate();
  }

  public String getTitle()
  {
    return AppLocal.getIntString("Menu.ProductsWarehouse");
  }

  private class WarehouseSerializerRead
    implements SerializerRead
  {
    private WarehouseSerializerRead()
    {
    }

    public Object readValues(DataRead paramDataRead)
      throws BasicException
    {
      return new Object[] { paramDataRead.getString(1), paramDataRead.getString(2), paramDataRead.getString(3), paramDataRead.getString(4), ((Object[])(Object[])jeditor.createValue())[1], paramDataRead.getDouble(5), paramDataRead.getDouble(6), paramDataRead.getDouble(7) };
    }
  }

  private class ReloadActionListener
    implements ActionListener
  {
    private ReloadActionListener()
    {
    }

    public void actionPerformed(ActionEvent paramActionEvent)
    {
      try
      {
        ProductsWarehousePanel.this.bd.actionLoad();
      }
      catch (BasicException localBasicException)
      {
      }
    }
  }
}

/* Location:           D:\PowerFulPOS-2.30.2\openbravopos.jar
 * Qualified Name:     com.openbravo.pos.inventory.ProductsWarehousePanel
 * JD-Core Version:    0.6.0
 */